layui.define([ 'form', 'laydate', 'table','rentingApi'], function(exports) {
    var form = layui.form;
    var rentingApi = layui.rentingApi;
    var index = layui.index;
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取身份证文件
                     */

                    var isEmpty = Common.fileRequire("#IdfileDataList");
                    var banknumber = Common.fileRequire("#banknumberDataList");
                    var rentingHouse = Common.fileRequire("#rentingHouseDataList");
                    var qualificationCertificate = Common.fileRequire("#qualificationCertificateDataList");

                    if(isEmpty){
                        Common.alert("身份证件附件必须上传");
                    }else if(banknumber){
                        Common.alert("银行卡材料信息附件必须上传");
                    }else if(qualificationCertificate){
                        Common.alert("相关证书附件必须上传");
                    }else {
                            rentingApi.addRenting($('#addForm'),function(){
                            parent.window.dataReload();
                            Common.info("添加成功");
                             Lib.closeFrame();
                        });
                    }
                });
            });
            $("#addButton-PandD").click(function(){
                form.on('submit(form)', function(){
                    /**
                     * 获取身份证文件
                     */

                    var isEmpty = Common.fileRequire("#IdfileDataList");
                   // var laborContract = Common.fileRequire("#laborContractDataList");
                    var rentingHouse = Common.fileRequire("#rentingHouseDataList");
                    var banknumber = Common.fileRequire("#banknumberDataList");
                    var qualificationCertificate = Common.fileRequire("#qualificationCertificateDataList");

                    if(isEmpty){
                        Common.alert("身份证件附件必须上传");
                    }else if(banknumber){
                        Common.alert("银行卡材料信息附件必须上传");
                    }else if(qualificationCertificate){
                        Common.alert("职业资格证书附件必须上传");
                    }else {
                        Common.openConfirm("确认申报?", function () {
                            rentingApi.savedeclaration($('#addForm'), function () {
                                parent.window.dataReload();
                                Common.info("保存并申报成功");
                                Lib.closeFrame();
                            });
                        }, null);
                    }
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
            $("#addRelatives").click(function(){
                form.on('submit(form)', function(){
                    rentingApi.addRelatives($('#addForm'),function(){
                        Common.info("添加成功");
                        window.parent.location.reload();
                        Lib.closeFrame();
                    });
                });
            });
            $("#addRelatives-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    			
    }
    exports('add',view);
});